<?php
/**
 * 本例演示上传单个文件，使用 putObject方法
 * author: JiangJun
 * CreateTime:2021/8/30 6:03 下午
 */

use Aws\S3\Exception\S3Exception;
use Aws\S3\S3Client;

require '../sqs/vendor/autoload.php';

$s3Client = new S3Client([
    'region' => 'ap-northeast-2',
    'version' => '2006-03-01'
]);


$bucket = 'jiang-bucket';
$file_Path = './girl.jpeg';
$key = '2021-08-31/girl88.jpeg'; // 遇到 / 的话，就会自动创建目录

try {

    $result = $s3Client->putObject([
        'Bucket' => $bucket,
        'Key' =>$key,
        'SourceFile' => $file_Path,
    ]);
} catch (S3Exception $e) {
    echo $e->getMessage() . "\n";
}

echo $key.',上传成功'.PHP_EOL;